#ifndef MATH_EXTENSION_H
#define MATH_EXTENSION_H

#include "Include.h"

class MathExtension{
public:
	static float SolveSecondDegree(float a, float b, float c, bool plus){
		float x;
		if (plus)
			x = (-b + sqrt(b*b - (4*a*c)))/(2*a);
		else
			x = (-b - sqrt(b*b - (4*a*c)))/(2*a);
		return x;
	}
	
	static float SolveThirdDegree(float a, float b, float c, float d){
		float x;
		float term1 = (-b*-b*-b)/(27*a*a*a);
		float term2 = b*c /(6*a*a);
		float term3 = -d/(2*a);
		float term4 = c/(3*a);
		float term5 = -b*b/(9*a*a);
		x = cuberoot(((term1+term2+term3)+sqrt((term1+term2+term3)+(cube(term4+term5)))))
		  + cuberoot(((term1+term2+term3)-sqrt((term1+term2+term3)+(cube(term4+term5)))))
		  - (b/3*a);
		return x;
	}
	
	static float cuberoot (float a){
		float x = pow(a, 1/3);
		return x;
	}
	
	static float cube(float a){
		float x = a*a*a;
		return x;
	}
};

#endif
